package com.chang.service.impl;

import com.chang.bean.Order;
import com.chang.common.bean.PageBean;
import com.chang.common.crud.BaseServiceImpl;
import com.chang.mapper.OrderMapper;

//import com.chang.mapper.UserMapper;

import com.chang.query.OrderQuery;
import com.chang.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: erp-api
 * @description:
 * @author: chang
 * @create: 2025-02-14 21h
 **/
@Service
public class OrderSericeImpl extends BaseServiceImpl<Order, OrderMapper> implements OrderService {

//    @Autowired
//    UserMapper userMapper;




//    @Transactional//管理事务的开启、提交或回滚。
//    @Override
//    public int save(Order entity) {
//        //检查订单是否存在
//        int c=OrderMapper.queryUserByUserName(entity.getAccount());
//        if(c>0)
//            throw new BusinessException("该账号已存在！");
//        //先保存用户
//        User user = new User(entity.getAccount(), entity.getPassword(),UserTyper.CUSTOMER_USER);
//        int rs=userMapper.save(user);
//        Assert.isZero(rs,"保存订单失败");
//        //保存客户
//        //设置客户id
//        entity.setId(user.getId());
//        return super.save(entity);
//    }

    /**
     * 分页查询
     * @param query
     * @return
     */
    @Override
    public PageBean query(OrderQuery query) {
        PageHelper.startPage(query.getPage(),query.getPageSize() );//紧跟查询
        List list =baseMapper.query(query);
        PageInfo pageInfo = new PageInfo(list);
        return new PageBean(query.getPage(), query.getPageSize(), pageInfo.getTotal(),list);
    }
}
